package com.school.aftersalemanagement.controller.ui.register;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.school.aftersalemanagement.R;
import com.school.aftersalemanagement.global.BaseToolBarActivity;
import com.school.aftersalemanagement.global.UserConfig;
import com.school.aftersalemanagement.service.UserService;
import com.school.aftersalemanagement.service.impl.UserServiceimpl;

import butterknife.BindView;
import butterknife.OnClick;

public class RegisterActivity extends BaseToolBarActivity {
    @BindView(R.id.register_acount)
    EditText registerAcount;
    @BindView(R.id.register_password)
    EditText registerPassword;
    private UserService userService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        setToolbarText("登录");
        userService = new UserServiceimpl(this,mHandler);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }
    private int REGISTER_SUCCEED = 1;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == REGISTER_SUCCEED) {
                showShort("登录成功");
                finish();
            }
        }
    };

    @OnClick({R.id.register_next})
    public void onViewClicked(View view) {
        String phone = registerAcount.getText().toString();
        switch (view.getId()) {
            case R.id.register_next:
                String password = registerPassword.getText().toString();
                TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
                String deviceId = tm.getDeviceId();
                String divice_token = UserConfig.getInstance(this).getDeviceToken();
                Log.d("pushon566",divice_token);
                userService.register(deviceId,phone,password,divice_token,REGISTER_SUCCEED);
                break;
        }
    }

}
